Add a current-value property and a setter for it. (#322735, Jorn Baayen)
authorMatthias Clasen <mclasen@redhat.com>
Mon, 16 Jan 2006 19:07:13 +0000 (19:07 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 16 Jan 2006 19:07:13 +0000 (19:07 +0000)
2006-01-16  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkradioaction.[hc]: Add a current-value property and a
setter for it.  (#322735, Jorn Baayen)

ChangeLog
ChangeLog.pre-2-10
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtkradioaction.c
gtk/gtkradioaction.h

index 616db4e89b1fb4b52f6cda8d0c5a2179b330d815..dd45ed56603216506d1a6c9b4472f0164791c991 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-16  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkradioaction.[hc]: Add a current-value property and a
+       setter for it.  (#322735, Jorn Baayen)
+       
 2006-01-16  Michael Natterer  <mitch@imendio.com>
 
        * gtk/gtkbutton.c: applied patch from maemo-gtk which adds a
index 616db4e89b1fb4b52f6cda8d0c5a2179b330d815..dd45ed56603216506d1a6c9b4472f0164791c991 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-16  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkradioaction.[hc]: Add a current-value property and a
+       setter for it.  (#322735, Jorn Baayen)
+       
 2006-01-16  Michael Natterer  <mitch@imendio.com>
 
        * gtk/gtkbutton.c: applied patch from maemo-gtk which adds a
index 2e043e571db4dbb97d39a55d310a8d5dcfd9b568..fe379700a1715c9d9a20265244b462d935717dcb 100644 (file)
@@ -2585,6 +2585,7 @@ gtk_radio_action_new
 gtk_radio_action_get_group
 gtk_radio_action_set_group
 gtk_radio_action_get_current_value
+gtk_radio_action_set_current_value
 <SUBSECTION Standard>
 GTK_TYPE_RADIO_ACTION
 GTK_RADIO_ACTION
index 9099cfed70c0dfda011308890d6fb6b04fc80a7e..cfe5043151eb6f316d0287fa7e672d8e9901e89f 100644 (file)
@@ -2448,6 +2448,7 @@ gtk_radio_action_get_current_value
 gtk_radio_action_get_group
 gtk_radio_action_get_type G_GNUC_CONST
 gtk_radio_action_new
+gtk_radio_action_set_current_value
 gtk_radio_action_set_group
 #endif
 #endif
index b2f60b46c55a4f35339ce05f944c6481345e924b..8d243f163cb1857e293fb0e4437b66992e895a8e 100644 (file)
@@ -56,7 +56,8 @@ enum
 {
   PROP_0,
   PROP_VALUE,
-  PROP_GROUP
+  PROP_GROUP,
+  PROP_CURRENT_VALUE
 };
 
 static void gtk_radio_action_init         (GtkRadioAction *action);
@@ -159,6 +160,24 @@ gtk_radio_action_class_init (GtkRadioActionClass *klass)
                                                        GTK_TYPE_RADIO_ACTION,
                                                        GTK_PARAM_WRITABLE));
 
+  /**
+   * GtkRadioAction:current-value:
+   *
+   * The value property of the currently active member of the group to which
+   * this action belongs. 
+   *
+   * Since: 2.10
+   */
+  g_object_class_install_property (gobject_class,
+                                  PROP_CURRENT_VALUE,
+                                   g_param_spec_int ("current-value",
+                                                    P_("The current value"),
+                                                    P_("The value property of the currently active member of the group to which this action belongs."),
+                                                    G_MININT,
+                                                    G_MAXINT,
+                                                    0,
+                                                    GTK_PARAM_READWRITE));
+
   /**
    * GtkRadioAction::changed:
    * @action: the action on which the signal is emitted
@@ -278,6 +297,10 @@ gtk_radio_action_set_property (GObject         *object,
          }
       }
       break;
+    case PROP_CURRENT_VALUE:
+      gtk_radio_action_set_current_value (radio_action,
+                                          g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -299,6 +322,10 @@ gtk_radio_action_get_property (GObject    *object,
     case PROP_VALUE:
       g_value_set_int (value, radio_action->private_data->value);
       break;
+    case PROP_CURRENT_VALUE:
+      g_value_set_int (value,
+                       gtk_radio_action_get_current_value (radio_action));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -355,6 +382,8 @@ gtk_radio_action_activate (GtkAction *action)
          tmp_action = tmp_list->data;
          tmp_list = tmp_list->next;
          
+          g_object_notify (G_OBJECT (tmp_action), "current-value");
+
          g_signal_emit (tmp_action, radio_action_signals[CHANGED], 0, radio_action);
        }
     }
@@ -485,5 +514,45 @@ gtk_radio_action_get_current_value (GtkRadioAction *action)
   return action->private_data->value;
 }
 
+/**
+ * gtk_radio_action_set_current_value:
+ * @action: a #GtkRadioAction
+ * @current_value: the new value
+ * 
+ * Sets the currently active group member to the member with value
+ * property @current_value.
+ *
+ * Since: 2.10
+ **/
+void
+gtk_radio_action_set_current_value (GtkRadioAction *action,
+                                    gint            current_value)
+{
+  GSList *slist;
+
+  g_return_if_fail (GTK_IS_RADIO_ACTION (action));
+
+  if (action->private_data->group)
+    {
+      for (slist = action->private_data->group; slist; slist = slist->next)
+       {
+         GtkRadioAction *radio_action = slist->data;
+
+         if (radio_action->private_data->value == current_value)
+            {
+              gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (radio_action),
+                                            TRUE);
+              return;
+            }
+       }
+    }
+
+  if (action->private_data->value == current_value)
+    gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+  else
+    g_warning ("Radio group does not contain an action with value '%d'",
+              current_value);
+}
+
 #define __GTK_RADIO_ACTION_C__
 #include "gtkaliasdef.c"
index 75a079819bc7ebb7f2205fb6be9dfa1ad5951446..d39648b4585719f20aefdc41ea361ccfc73cd773 100644 (file)
@@ -77,7 +77,8 @@ GSList         *gtk_radio_action_get_group         (GtkRadioAction        *actio
 void            gtk_radio_action_set_group         (GtkRadioAction        *action,
                                                     GSList                *group);
 gint            gtk_radio_action_get_current_value (GtkRadioAction        *action);
-
+void            gtk_radio_action_set_current_value (GtkRadioAction        *action,
+                                                    gint                   current_value);
 
 G_END_DECLS